# -*- coding:utf-8 -*-
# @Time : 21-10-25 上午1:58 
# @Author : zdy
# @File : Log.py
# desc:
import logging
from logging import handlers

class Logger(object):
    def __init__(self):
        self.logger = logging.getLogger("log")
        self.logger.setLevel(logging.INFO)

    def setConfig(self, file):
        """
        初始化设置
        :param file:日志保存的位置
        :return:
        """
        handler = handlers.TimedRotatingFileHandler(filename=file, when="D", backupCount=10, encoding="utf-8")
        # backupCount备份的最大个数，查过会自动删除；when 间隔的时间单位，其中S秒，M分，H小时，D天，W星期,生成的第二个文件名会待、带时间
        formatter = logging.Formatter("%(asctime)s - %(levelname)s: %(message)s")
        handler.setFormatter(formatter)
        self.logger.addHandler(handler)

    def debug(self, category, message):
        self.logger.debug(category + ":" + message)

    def info(self, category, message):
        self.logger.info(category + ":" + message)

    def warn(self, category, message):
        self.logger.warning(category + ":" + message)

    def critical(self, category, message):
        self.logger.critical(category + ":" + message)

    def error(self, category, message):
        self.logger.error(category + ":" + message)


log = Logger()
